<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>div1</div>
  <div>div2</div>
  <div>div3</div>
  <div>div4</div>
  <script>

    let i = 10;

    let fn1 = function () {
      console.log(i);
    }
    i = 20
    i = 30
    // 函数是调用时执行的代码块
    fn1()

    var a = [];
    for (var i = 0; i < 10; i++) {
      a[i] = function () {
        console.log(i);
      };
    }
    a[6]();

    

    var divArr = document.querySelectorAll("div")
    console.log(divArr)
    for (var i = 0; i < divArr.length; i++) {
      divArr[i].onclick = function () {
        console.log(i)
        divArr[i].style.color = "red"
      }
    }
  </script>
</body>

</html>